package org.jeecg.modules.api.geo.controller;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.api.geo.service.IBimApiGeoService;
import org.jeecg.modules.core.constant.ApiBusinessTypeEnum;
import org.jeecg.modules.geo.model.param.GeoAreaParam;
import org.jeecg.modules.geo.model.vo.GeoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@Api(tags = "api接口查询")
@Slf4j
@RestController
@RequestMapping("/api")
public class ApiGeoController {

    @Autowired
    private IBimApiGeoService bimApiGeoService;

    @GetMapping("/bim")
    @ApiOperation(value = "查询业务系统数据整合统一样式返回", notes = "查询业务系统数据整合统一样式返回")
    public Result<?> getGeoInfo(@RequestParam("projectId") Long projectId, @RequestParam("appCode") String appCode, HttpServletRequest httpServletRequest) {
        // 获取bim信息
        GeoVO geoInfo = bimApiGeoService.getGeoInfo(projectId, appCode, httpServletRequest);
        return Result.OK(geoInfo);
    }

    @PostMapping(path = "/geo")
    public Result<?> addGeo(@RequestBody GeoAreaParam geoAreaParam, HttpServletRequest httpServletRequest) {
        if (geoAreaParam.getAppCode() == null || CollectionUtils.isEmpty(geoAreaParam.getArea())) {
            throw new JeecgBootException("参数有误，请重新输入");
        }
        bimApiGeoService.addGeoInfo(geoAreaParam, httpServletRequest);
        return Result.OK();
    }

    @GetMapping(value = "/queryProject")
    @ApiOperation(value = "应用项目列表查询", notes = "应用项目列表查询")
    public String queryProjects(@RequestParam(name = "projectApiId") Integer projectApiId, HttpServletRequest httpServletRequest) {
        if (ObjectUtil.isNull(projectApiId)) {
            throw new JeecgBootException("apiId参数有误，请重新输入");
        }
        return bimApiGeoService.queryProjectForApiId(projectApiId, httpServletRequest);
    }

    @RequestMapping(path = "/queryApi", method = RequestMethod.GET)
    @ApiOperation(value = "查询指定业务类型对应的第三方业务系统的数据查询接口", notes = "查询指定业务类型对应的第三方业务系统的数据查询接口")
    public String queryApi(@RequestParam(value = "businessType") String businessType, HttpServletRequest httpServletRequest) {
        return bimApiGeoService.queryApi(businessType, httpServletRequest);
    }
}
